/*
 * Create Author  : jinpeng.chen
 * Create Date    : 2016-12-13
 * Project        : springboot-chapter5
 * File Name      : LvmamaAutoConfiguration.java
 *
 * Copyright (c) 2010-2015 by Shanghai HanTao Information Co., Ltd.
 * All rights reserved.
 *
 */
package com.lvmama.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 功能描述:  <p>
 *
 * @author : jinpeng.chen <p>
 * @version 1.0 2016-12-13
 * @since springboot-chapter5 1.0
 */
@Configuration
@EnableConfigurationProperties(LvmamaProperties.class)
@ConditionalOnClass(LvmamaService.class)
@ConditionalOnProperty(prefix = "lvmama", value = "enabled", matchIfMissing = true)
public class LvmamaAutoConfiguration {

    @Autowired
    private LvmamaProperties lvmamaProperties;

    @Bean
    @ConditionalOnMissingBean(LvmamaService.class)
    public LvmamaService lvmamaService() {
        LvmamaService lvmamaService = new LvmamaService();
        lvmamaService.setMsg(lvmamaProperties.getMsg());
        return lvmamaService;
    }
}
